// config/swagger.js
const swaggerJSDoc = require('swagger-jsdoc');

// Swagger定义
const swaggerDefinition = {
  openapi: '3.0.0',
  info: {
    title: '待办事项与SQL生成API',
    version: '1.0.0',
    description: '基于MVC架构的待办事项管理和自然语言转SQL的API文档',
    contact: {
      name: '课程项目团队',
    },
  },
  servers: [
    {
      url: 'http://localhost:3000/',
      description: '开发服务器',
    },
  ],
  components: {
    schemas: {
      Todo: {
        type: 'object',
        required: ['id', 'title'],
        properties: {
          id: {
            type: 'integer',
            description: '待办事项ID',
          },
          title: {
            type: 'string',
            description: '待办事项标题',
          },
          completed: {
            type: 'boolean',
            description: '是否完成',
            default: false,
          },
          created_at: {
            type: 'string',
            format: 'date-time',
            description: '创建时间',
          },
        },
        example: {
          id: 1,
          title: '完成MVC重构作业',
          completed: false,
          created_at: '2023-10-01T12:00:00Z',
        },
      },
    },
  },
};

// 指定要检查的API路由位置
const options = {
  swaggerDefinition,
  apis: ['./routes/*.js'], // 扫描所有控制器文件中的注释
};

const swaggerSpec = swaggerJSDoc(options);

module.exports = swaggerSpec;